home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: giuliano@ix.netcom.com(Giuliano Carlini)
- Newsgroups: comp.lang.c++
- Subject: Re: "Pure virtual function called" error with Sparcworks
- Date: 11 Apr 1996 06:59:29 GMT
- Organization: Netcom
- Message-ID: <4kiakh$mjq@dfw-ixnews8.ix.netcom.com>
- References: <316B8607.41C67EA6@jpmorgan.com>
- NNTP-Posting-Host: lbx-ca7-14.ix.netcom.com
- X-NETCOM-Date: Thu Apr 11 1:59:29 AM CDT 1996
-
- In <316B8607.41C67EA6@jpmorgan.com> Oliver Peck
- <peck_oliver@jpmorgan.com> writes:
- >
- >I am using V4.0.1 of the Sparcworks C++ compiler.
- >
- >A program is occasionally crashing with the message:-
- >
- >"**** Pure virtual function called"
- >
- >Does anyone know what this may mean?
- >
- >
- >Thanks in advance.
- >
- >Oliver
-
- This usually means you've done something like this:
-
- class Base {
- public:
- virtual void foo() = 0;
- };
-
- class Derived : public Base {
- virtual void foo(){ ... };
- };
-
- main()
- {
- Derived* d;
-
- d = new Derived;
- delete d;
- d->foo();
- }
-
- What happens is that when you delete D, that first calls the destructor
- for Derived, and then that for Base. For reasons that get ugly, most
- vendors replace the v-table pointer at the start of the destructor with
- the v-table for that class. So, Base:~Base replaces d's v-table pointer
- with the v-table for class Base. But, class Base doesn't provide an
- implementation for foo. So, there is nothing for the foo entry in the
- Base v-table to point to. Or, so you'd think. What happens is that the
- compiler secretely provided Base::foo for you. It shrieks:
- **** Pure virtual function called
- and then exits.
-
- There are other ways to get this error, but this is the most common
- that I've seen.
-
- g
-
-